﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class PriorityQueue<T>  
  
{

    private List<T> tree;
    private IComparer<T> comparer;
    
    public PriorityQueue()
    {
        tree = new List<T>();
        tree.Add(default(T));
        comparer = Comparer<T>.Default;
    }

    public void Push(T element)
    {
        tree.Add(element);
        int now = tree.Count - 1;
        while (now > 1)
        {
            if (comparer.Compare(tree[now], tree[now / 2]) > 0)
            {
                T tmp = tree[now / 2];
                tree[now / 2] = tree[now];
                tree[now] = tmp;
            }
            else break;
            now /= 2;
        }
    }

    public void Pop()
    {
        tree[1] = tree[tree.Count - 1];
        tree.RemoveAt(tree.Count - 1);
        int now = 1;
        while (now < tree.Count)
        {
            if (2 * now >= tree.Count) break;
            if (2 * now + 1 >= tree.Count || comparer.Compare(tree[2 * now], tree[2 * now + 1]) > 0)
            {
                if (comparer.Compare(tree[2 * now], tree[now]) > 0)
                {
                    T tmp = tree[2 * now];
                    tree[2 * now] = tree[now];
                    tree[now] = tmp;
                }
                else break;
                now = 2 * now;
            }
            else
            {
                if (comparer.Compare(tree[2 * now + 1], tree[now]) > 0)
                {
                    T tmp = tree[2 * now + 1];
                    tree[2 * now + 1] = tree[now];
                    tree[now] = tmp;
                }
                else break;
                now = 2 * now + 1;
            }
        }
    }

    public T Top()
    {
        return tree[1];
    }

    public int Count
    {
        get
        {
            return tree.Count;
        }
    }

    public override string ToString()
    {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < tree.Count; i++)
        {
            sb.Append(((tree[i]!=null)?tree[i].ToString():"null") + " ");
        }
        return sb.ToString();
    }

    public IEnumerator<T> GetEnumerator()
    {
        for (int i = 0; i < tree.Count; i++)
        {
    //        Console.WriteLine(i + " -> " + tree[i] + " -> " + tree.Count);
            yield return tree[i];
        }
    }
 
}

class Program
{
    static void Main(string[] args)
    {

        PriorityQueue<string> queue = new PriorityQueue<string>();

        while (true)
        {
            string cmd = Console.ReadLine();
            if (cmd.StartsWith("add"))
            {
                queue.Push(cmd.Substring(cmd.IndexOf(" ") + 1));
                //Console.WriteLine(queue.ToString());
            }
            else if (cmd.StartsWith("get"))
            {
                Console.WriteLine(queue.Top());
            }
            else if (cmd.StartsWith("del"))
            {
                queue.Pop();
            }
            else if (cmd.StartsWith("getall"))
            {
                foreach (var item in queue)
                {
                    Console.WriteLine(item.ToString());
                }
            }
        }
    }
}
